package Day28;


import java.lang.reflect.Constructor;
import java.lang.reflect.Field;

public class Demo05 {
    public static void main(String[] args) throws Exception {
        Class c = Class.forName("Day28.Person");
        Constructor ct = c.getConstructor();
        Object o = ct.newInstance();

        Field phoneNumber = c.getField("phoneNumber");//不是私有的可以   私有的不行
        phoneNumber.set(o,"123456");
        System.out.println(o);

        //如果是私有的
        Field name = c.getDeclaredField("name");
        name.setAccessible(true);
        name.set(o,"王二");
        System.out.println(o);
    }
}
